package me.toalec.RankUp.Permissions;

import java.util.ArrayList;

import me.toalec.RankUp.util.Utility;

import org.bukkit.entity.Player;
import ru.tehkode.permissions.PermissionGroup;
import ru.tehkode.permissions.PermissionManager;

public class PermissionsEx extends PermissionsBase{

	PermissionsEx(){
		
		pm = ru.tehkode.permissions.bukkit.PermissionsEx.getPermissionManager();
		Utility.printConsole("PermissionsEx initialized!");
	}
	
	@Override
	boolean hasPermission(Player player, String node) {
		return pm.has(player, node);
	}

	@Override
	boolean isValidPlayer(String playerName, Player worldReference) {
		return (pm.getUser(playerName) != null);
	}

	@Override
	boolean isValidGroup(String groupName, Player worldReference) {
		return (groupName != null && pm.getGroup(groupName) != null);
	}

	@Override
	ArrayList<String> getGroupName(String playerName, Player worldReference) {
		ArrayList<String> groupNames = new ArrayList<String>();
		PermissionGroup[] pg = pm.getUser(playerName).getGroups();
		for(int i = 0; i < pg.length; i++){
			groupNames.add(pg[i].getName());
		}
		return groupNames;
	}

	@Override
	void removeGroup(String playerName, Player worldReference, String startingGroup) {
		pm.getUser(playerName).removeGroup(startingGroup);		
	}

	@Override
	void addGroup(String playerName, Player worldReference, String endingGroup) {
		pm.getUser(playerName).addGroup(endingGroup);				
	}

	@Override
	void addPermission(Player player, String node) {
		pm.getUser(player).addPermission(node);
		
	}
	//PermissionsEx PermissionManager, not be confused with RankUp's PermissionsManager
	private PermissionManager pm;

}
